package com.example.mymvplibrary.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;


public abstract class BaseAdapter<DATA> extends RecyclerView.Adapter<BaseViewHolder>{
    protected List<DATA>datas;
    protected Context context;
    protected LayoutInflater layoutInflater;
    private int layoutId;


    public BaseAdapter(List<DATA> datas, Context context,int layoutId) {
        this.datas = datas;
        this.context = context;
        layoutInflater=LayoutInflater.from(context);
        this.layoutId=layoutId;
    }


    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(layoutInflater.inflate(layoutId,parent,false));
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        bindData(holder,datas.get(position),position);
    }

    public abstract void bindData(BaseViewHolder holder, DATA data,int pos);


    @Override
    public int getItemCount() {
        return datas.size();
    }


}
